<?php include("header.php"); ?>	        
	<div id="body">
            <?php 
                echo '<table>';
                echo '<tr><td>';
                echo '<div id="container">';
                echo '<div id="body">';
                echo '<h2>'.$media['title'].'</h2>';
                if($user['user_id'] == $this->session->userdata('user_id'))
                    echo '<p><a href="'. site_url("media/edit/".$media['media_id']).'">Muokkaa</a></p>';
                echo '<iframe width="420" height="315" src="http://www.youtube.com/embed/' . $media['source_id'] .'?>" frameborder="0" allowfullscreen></iframe>';
                echo '</div></div>';
                echo '</td></tr>';
                echo '<tr><td>'; 
                
                echo '<div id="container">';
                echo '<div id="body">';
                echo '<table width="100%"><tr><td VALIGN="top">';
               
                echo '<p>Videon lataaja: <a href="'. site_url("profile/view/".$user['user_id']) . '">'.$user['user_name'].'</a></p>'; 
                
                echo '<p>Kategoriat:';
                foreach($tags as $tag)
                {
                    echo '&nbsp;&nbsp;<a href="'. site_url("search/search_tag/".$tag['tag_id']).'">'.$tag['name'].'</a>';                    
                }
                if($this->session->userdata('logged_in'))
                {
                    echo '&nbsp;&nbsp;<a href="javascript:void(0)" id="toggle_tag_adder" onClick="document.getElementById(\'tag_adder\').style.visibility=\'visible\'; document.getElementById(\'toggle_tag_adder\').style.visibility=\'hidden\';">Lisää</a>';
                }
                echo '</p>';                
                if($this->session->userdata('logged_in'))
                {
                    echo '<div id="tag_adder" style="visibility:hidden;">';    
                    echo form_open('media/add_tags');
                    echo form_hidden('media_id', $media['media_id']);
                    echo form_input('added_tags', '');
                    echo form_submit('mysubmit', 'Lisää kategoria');
                    echo form_close();
                    echo '</div>';
                }
                
                echo '</td><td width="75px"  VALIGN="top">';
                if(($ratings['has_voted'] == '0' || $ratings['has_voted'] == null) && $this->session->userdata('logged_in'))
                {
                    echo '<span style="background-color:#aaaaaa; font-size:20px; line-height:30px;" width="75px"><a href="'. site_url("media/add_vote/".$media['media_id'].'/1') . '">'.img('media/thumb_up.png').'</a>&nbsp;&nbsp;<a href="'. site_url("media/add_vote/".$media['media_id'].'/-1') . '">'.img('media/thumb_down.png').'</a></span>';
                }
                if($ratings['vote_count'] > '0')
                {
                    echo '<div style="width:75px;">';
                    echo '<div style="display:inline-block; height:10px; background-color:#ff0000; width:'.$ratings['dislikes'] / $ratings['vote_count'] * '100' .'%;"></div>';
                    echo '<div style="display:inline-block; height:10px; background-color:#00ff00; width:'.$ratings['likes'] / $ratings['vote_count'] * '100'  .'%;"></div>';
                    echo '<p>'.$ratings['vote_count'].' ääntä</p>';
                    echo'</div>';
                }
                echo '</td></tr></table>';
                echo '</div>';
                echo '</div>';
                echo '</td></tr>';
                
                
                
                echo '<tr width="420px"><td>';
                echo '<div id="container">';
                echo '<div id="body">';
                echo '<h3>Kommentit</h3>';
                foreach($comments as $comment)
                {
                    echo '<p><a href="'. site_url("profile/view/".$comment['user_id']) . '">'.$comment['user_name'].'</a>'.'&nbsp;&nbsp;&nbsp;'.$comment['comment'].'</p>';
                }
                
                if($this->session->userdata('logged_in'))
                {
                    echo form_open('media/add_comment');                  
                    echo '<table width="500px">';                      
                    echo '<tr>';          
                    echo '<td>';
                    echo form_hidden('media_id', $media['media_id']);
                    $data = array(
                      'name'        => 'comment',
                      'id'          => 'comment',
                      'value'       => '',
                      'rows'        => '4',
                      'cols'        => '40',
                      'style'       => 'width:400px',
                    );
                    echo form_textarea($data);
                    echo '</td>';
                    echo '</tr>';   
                    echo '<tr><td>'.form_submit('mysubmit', 'Lähetä kommentti').'</td></tr>';
                    echo '</table>';
                    echo form_close();
                }
                echo '</div>';
                echo '</div>';
                echo '</td></tr>';
                
                echo '</table>';
            ?>
        </div>
<?php include("footer.php"); ?>  